package com.tfswx.jkgl.designer.api;

import com.alibaba.fastjson.JSON;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.tfswx.jkgl.designer.dto.jkgl.*;
import com.tfswx.jkgl.designer.service.JkglService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ricky
 * @date 2021/12/10
 */
@Api(tags = "接口管理")
@RestController
@RequestMapping("api")
@ApiSupport(order = 10)
public class JkglController {

    @Resource
    private JkglService jkglService;

    @ApiOperation("添加接口定义")
    @PostMapping("/addJkdy")
    @ApiOperationSupport(order = 10)
    public String addJkdy(@RequestBody @Validated JkdyAddInputDTO inputDTO) {
        inputDTO.setRcpz(JSON.toJSONString(inputDTO.getRcpz()));
        inputDTO.setCcpz(JSON.toJSONString(inputDTO.getCcpz()));
        inputDTO.setRcsl(JSON.toJSONString(inputDTO.getRcsl()));
        inputDTO.setCcsl(JSON.toJSONString(inputDTO.getCcsl()));
        return jkglService.addJkdy(inputDTO);
    }

    @ApiOperation("删除接口定义")
    @PostMapping("/deleteJkdy")
    @ApiOperationSupport(order = 20)
    public Boolean deleteJkdy(@RequestBody @Validated JkdyDeleteInputDTO inputDTO) {
        return jkglService.deleteJkdy(inputDTO);
    }

    @ApiOperation("修改接口定义")
    @PostMapping("/updateJkdy")
    @ApiOperationSupport(order = 30)
    public Boolean updateJkdy(@RequestBody @Validated JkdyUpdateInputDTO inputDTO) {
        inputDTO.setRcpz(JSON.toJSONString(inputDTO.getRcpz()));
        inputDTO.setCcpz(JSON.toJSONString(inputDTO.getCcpz()));
        inputDTO.setRcsl(JSON.toJSONString(inputDTO.getRcsl()));
        inputDTO.setCcsl(JSON.toJSONString(inputDTO.getCcsl()));
        return jkglService.updateJkdy(inputDTO);
    }

    @ApiOperation("设置接口启用状态")
    @PostMapping("/setJkqyzt")
    @ApiOperationSupport(order = 31)
    public Boolean setJkqyzt(@RequestBody @Validated JkqyztSetInputDTO inputDTO) {
        return jkglService.setJkqyzt(inputDTO);
    }

    @ApiOperation("设置接口状态")
    @PostMapping("/setJkzt")
    @ApiOperationSupport(order = 32)
    public Boolean setJkzt(@RequestBody @Validated JkztSetInputDTO inputDTO) {
        return jkglService.setJkzt(inputDTO);
    }

    // @ApiOperation("设置接口分类")
    // @PostMapping("/setJkflbm")
    // @ApiOperationSupport(order = 32)
    // public Boolean setJkflbm(@RequestBody @Validated JkflbmSetInputDTO inputDTO) {
    //     return jkglService.setJkflbm(inputDTO);
    // }

    @ApiOperation("查询接口定义")
    @PostMapping("/queryJkdy")
    @ApiOperationSupport(order = 40)
    public List<JkdyQueryResult> queryJkdy(@RequestBody @Validated JkdyQueryInputDTO inputDTO) {
        return jkglService.queryJkdy(inputDTO);
    }

    @ApiOperation("获取接口定义")
    @PostMapping("/getJkdy")
    @ApiOperationSupport(order = 41)
    public JkdyGetOutputDTO getJkdy(@RequestBody @Validated JkdyGetInputDTO inputDTO) {
        return jkglService.getJkdy(inputDTO);
    }

    @ApiOperation("复制接口定义")
    @PostMapping("/copyJkdy")
    @ApiOperationSupport(order = 42)
    public void copyJkdy(@RequestBody @Validated JkdyCopyInputDTO inputDTO) {
        jkglService.copyJkdy(inputDTO);
    }
}
